package org.yoao.crm.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.yoao.crm.DBManager.DBManager;
import org.yoao.crm.bean.Customer;
import org.yoao.crm.tools.DaoUtil;
import org.yoao.crm.tools.TimeTool;

/**
 * @author yxwonline.com
 * @description
 * @date 2010-7-31 下午11:43:27
 */
public class CustomerDAO extends DBManager {
	private static final Logger log = Logger.getLogger(CustomerDAO.class);

	public Customer findCustomerById(String customerId) throws Exception {
		String sql = "select * from customer where customerId='" + customerId
				+ "'";
		return findSingle(querySingleRow(sql));
	}

	public Customer findByName(String customerName) throws Exception {
		String sql = "select * from customer where customerName='"
				+ customerName + "'";
		return findSingle(querySingleRow(sql));
	}

	public Customer findByNameNoCustomerId(String customerName,
			String customerId) throws Exception {
		String sql = "select * from customer where customerName='"
				+ customerName + "' and customerId <> '" + customerId + "'";
		return findSingle(querySingleRow(sql));
	}

	public Customer findById(String id) throws Exception {
		String sql = "select * from customer where id=" + id;
		return findSingle(querySingleRow(sql));
	}

	public Customer findCustomerByMobile(String mobile) throws Exception {
		Customer customer = null;
		String[] mobiles = null;
		if (mobile.contains(",")) {
			mobiles = mobile.split(",");
		} else if (mobile.contains("，")) {
			mobiles = mobile.split("，");
		} else if (mobile != null && !mobile.trim().equals("")) {
			mobiles = new String[1];
			mobiles[0] = mobile;
		}

		if (mobiles != null) {
			for (String mb : mobiles) {
				String sql = "select * from customer where mobile like '%" + mb
						+ "%'";
				customer = findSingle(querySingleRow(sql));
				if (customer != null) {
					return customer;
				}
			}
		}
		return customer;
	}

	public Customer findCustomerByMobileNoCustomerId(String mobile,
			String customerId) throws Exception {
		Customer customer = null;
		String[] mobiles = null;
		if (mobile.contains(",")) {
			mobiles = mobile.split(",");
		} else if (mobile.contains("，")) {
			mobiles = mobile.split("，");
		} else if (mobile != null && !mobile.trim().equals("")) {
			mobiles = new String[1];
			mobiles[0] = mobile;
		}

		if (mobiles != null) {
			for (String mb : mobiles) {
				String sql = "select * from customer where mobile like '%" + mb
						+ "%' and customerId <> '" + customerId + "'";
				customer = findSingle(querySingleRow(sql));
				if (customer != null) {
					return customer;
				}
			}
		}
		return customer;
	}

	public Customer findCustomerByNameAndMobile(String customerName,
			String mobile) throws Exception {
		Customer customer = null;
		String[] mobiles = null;
		if (mobile.contains(",")) {
			mobiles = mobile.split(",");
		} else if (mobile != null && !mobile.trim().equals("")) {
			mobiles = new String[1];
			mobiles[0] = mobile;
		}

		if (mobiles != null) {
			for (String mb : mobiles) {
				String sql = "select * from customer where mobile like '%" + mb
						+ "%' and customerName='" + customerName + "'";
				customer = findSingle(querySingleRow(sql));
				if (customer != null) {
					return customer;
				}
			}
		}
		return customer;
	}

	public String findMaxCustomerCode() throws Exception {
		String sql = "select MAX(customerID) as CUSTOMERID from customer";
		return querySingleValue(sql);
	}

	public Customer findShowById(String customerId) throws Exception {
		String sql = "select customer.id, customer.customerId, customer.idCard, customer.customerName, customer.companyName, "
				+ "customer.province, customer.city, customer.phone, customer.mobile, customer.QQ, "
				+ "customer.email, customer.birthday, customer.isNew, customer.userSno, "
				+ "baseuser.nickName as nickName, "
				+ "baseuser.roleId, userRole.roleName, customer.createTime, customer.modifyTime, "
				+ "customer.memo, customer.type from customer "
				+ "left join baseuser on baseuser.userName = customer.userSno "
				+ "left join userRole on userRole.roleId = baseuser.roleId "
				+ "where customer.customerId='" + customerId + "'";
		return findSingle(querySingleRow(sql));
	}

	private Customer findSingle(Map data) throws Exception {
		Customer customer = null;
		if (data != null && !data.isEmpty()) {
			customer = new Customer();
			customer.setId(Integer.parseInt(data.get("ID").toString()));
			customer.setCustomerId((String) data.get("CUSTOMERID"));
			customer.setCustomerName((String) data.get("CUSTOMERNAME"));
			customer.setIdCard((String) data.get("IDCARD"));
			customer.setCompanyName((String) data.get("COMPANYNAME"));
			customer.setProvince((String) data.get("PROVINCE"));
			customer.setCity((String) data.get("CITY"));
			customer.setPhone((String) data.get("PHONE"));
			customer.setMobile((String) data.get("MOBILE"));
			customer.setQQ((String) data.get("QQ"));
			customer.setEmail((String) data.get("EMAIL"));
			customer.setBirthday((String) data.get("BIRTHDAY"));
			customer.setIsNew(Integer.parseInt(data.get("ISNEW").toString()));
			customer.setUserSno((String) data.get("USERSNO"));
			customer.setRoleId((String) data.get("ROLEID"));
			customer.setCreateTime((String) data.get("CREATETIME"));
			customer.setModifyTime((String) data.get("MODIFYTIME"));
			customer.setMemo((String) data.get("MEMO"));
			customer.setType((String) data.get("TYPE"));
			if (data.get("NICKNAME") != null)
				customer.setNickName((String) data.get("NICKNAME"));
			if (data.get("ROLENAME") != null)
				customer.setRoleName((String) data.get("ROLENAME"));
		}
		return customer;
	}

	public int getExportCount(String customerId, String where) throws Exception {
		String sql = "select count(distinct customer.id) as customerCount from customer "
				+ "left join baseuser on baseuser.userName = customer.userSno "
				+ "left join userRole on userRole.roleId = baseuser.roleId "
				+ "left join customerAttributes on customerAttributes.customerId=customer.customerId where 1=1 ";
		if (customerId != null && !customerId.trim().equals("")) {
			customerId = "'" + customerId.replaceAll(",", "','") + "'";
			sql += " and customer.customerId in(" + customerId + ")";
		}
		if (where != null && !where.trim().equals(""))
			sql += " and " + where;
		String result = querySingleValue(sql);
		if (result == null || result.trim().equals(""))
			result = "0";
		return Integer.parseInt(result);
	}

	public int getDataCount(Map map) throws Exception {
		String sql = "select count(distinct customer.id) as customerCount from customer "
				+ "left join customerAttributes on customerAttributes.customerId = customer.customerId ";
		String where = " where ";
		if (map != null && !map.isEmpty()) {
			Iterator iter = map.keySet().iterator();
			while (iter.hasNext()) {
				String key = iter.next().toString();
				String value = map.get(key).toString();
				if (key.contains(".")) {
					if (key.contains(" LIKE ")) {
						where = where + key + " '%" + value + "%' and ";
					} else if (key.contains(" >") || key.contains(" <")) {
						where = where + key + value + " and ";
					} else {
						where = where + key + "='" + value + "' and ";
					}
				} else {
					if (key.contains(" LIKE ")) {
						where = where + "customer." + key + " '%" + value
								+ "%' and ";
					} else if (key.contains(" >") || key.contains(" <")) {
						if (key.contains("DATEDIFF(")) {
							where = where
									+ key.replaceAll("modifyTime",
											"customer.modifyTime") + value
									+ " and ";
						} else {
							where = where + "customer." + key + value + " and ";
						}
					} else {
						where = where + "customer." + key + "='" + value
								+ "' and ";
					}
				}
			}
		}
		if (where.endsWith(" and "))
			where = where.substring(0, where.length() - 4);
		if (where.equals(" where "))
			where = "";
		sql += where;
		String result = querySingleValue(sql);
		if (result == null || result.trim().equals(""))
			result = "0";
		return Integer.parseInt(result);
	}

	public List findAll() throws Exception {
		String sql = "select * from customer";
		return query(sql);
	}

	public List findExpordData(String customerId, String where)
			throws Exception {
		String sql = "select distinct customer.customerId, customer.customerName, customer.idCard, customer.companyName, "
				+ "customer.province, customer.city, customer.phone, customer.mobile, customer.qq, "
				+ "customer.email, customer.birthday, customerAttributes.state, customerAttributes.signature, "
				+ "customerAttributes.signTime, customerAttributes.amount, customerAttributes.payTime, "
				+ "customer.userSno, customer.roleId, customer.createTime, customer.modifyTime, customer.memo, customer.type "
				+ "from customer "
				+ "left join baseuser on baseuser.userName = customer.userSno "
				+ "left join userRole on userRole.roleId = baseuser.roleId "
				+ "left join customerAttributes on customerAttributes.customerId=customer.customerId "
				+ "where 1=1 ";
		if (customerId != null && !customerId.trim().equals("")) {
			customerId = "'" + customerId.replaceAll(",", "','") + "'";
			sql += " and customer.customerId in(" + customerId + ")";
		}
		if (where != null && !where.trim().equals(""))
			sql += " and " + where;
		return queryMultiColumn(sql);
	}

	public List findAllMobile(String id) throws Exception {
		String sql = "select distinct mobile from customer";
		if (id != null && !id.trim().equals(""))
			sql += " where id in(" + id + ")";
		return querySingleColumn(sql);
	}

	public List find(int startRow, int endRow, Map map) throws Exception {
		String sql = "select distinct top "
				+ endRow
				+ " customer.id, customer.customerId, customer.customerName, customer.idCard, "
				+ "customer.companyName, customer.province, customer.city, customer.phone, "
				+ "customer.mobile, customer.QQ, customer.email, customer.birthday, customer.isNew, "
				+ "baseuser.nickName as userSno, userRole.roleName as roleId, customer.createTime, customer.modifyTime, "
				+ "customer.memo, customer.type from customer "
				+ "left join customerAttributes on customerAttributes.customerId = customer.customerId "
				+ "left join baseuser on baseuser.userName = customer.userSno "
				+ "left join userRole on userRole.roleId = baseuser.roleId "
				+ "where customer.id not in(";
		String filterSql = "select top " + startRow
				+ " c2.id from customer as c2 ";

		String where = "";
		String fwhere = "";

		if (map != null && !map.isEmpty()) {
			Iterator iter = map.keySet().iterator();
			while (iter.hasNext()) {
				String key = iter.next().toString();
				String value = map.get(key).toString();
				if (key.contains(".")) {
					if (key.contains(" LIKE ")) {
						where = where + key + " '%" + value + "%' and ";
						fwhere = fwhere + key + " '%" + value + "%' and ";
					} else if (key.contains(" >") || key.contains(" <")) {
						where = where + key + value + " and ";
						fwhere = fwhere + key + value + " and ";
					} else {
						where = where + key + "='" + value + "' and ";
						fwhere = fwhere + key + "='" + value + "' and ";
					}
				} else {
					if (key.contains(" LIKE ")) {
						where = where + "customer." + key + " '%" + value
								+ "%' and ";
						fwhere = fwhere + "c2." + key + " '%" + value
								+ "%' and ";
					} else if (key.contains(" >") || key.contains(" <")) {
						if (key.contains("DATEDIFF(")) {
							where = where
									+ key.replaceAll("modifyTime",
											"customer.modifyTime") + value
									+ " and ";
							fwhere = fwhere
									+ key.replaceAll("modifyTime",
											"c2.modifyTime") + value + " and ";
						} else {
							where = where + "customer." + key + value + " and ";
							fwhere = fwhere + "c2." + key + value + " and ";
						}
					} else {
						where = where + "customer." + key + "='" + value
								+ "' and ";
						fwhere = fwhere + "c2." + key + "='" + value + "' and ";
					}
				}
			}
		}

		if (where.endsWith(" and "))
			where = where.substring(0, where.length() - 4);
		if (where.equals(""))
			where = null;
		if (fwhere.endsWith(" and "))
			fwhere = fwhere.substring(0, fwhere.length() - 4);
		if (fwhere.equals(""))
			fwhere = null;

		if (where == null) {
			sql = sql + filterSql
					+ " order by c2.id desc) order by customer.id desc";
		} else {
			filterSql = filterSql + " where " + fwhere;
			sql = sql + filterSql + " order by c2.id desc) and " + where
					+ " order by customer.id desc";
		}
		return query(sql);
	}

	private List find(String sql) throws Exception {
		List list = queryMultiColumn(sql);
		List result = null;
		if (list != null && !list.isEmpty()) {
			result = new ArrayList();
			for (int i = 0; i < list.size(); i++) {
				Map map = (Map) list.get(i);
				Customer customer = findSingle(map);
				if (customer == null)
					customer = new Customer();
				result.add(customer);
			}
		}
		return result;
	}

	private List query(String sql) {
		log.debug(sql);
		Connection con = null;
		ResultSet rs = null;
		Statement stmt = null;
		List result = new ArrayList();
		try {
			con = getConnection();
			stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
					ResultSet.CONCUR_READ_ONLY);
			rs = stmt.executeQuery(sql);
			ResultSetMetaData rsmd = rs.getMetaData();
			int columnCount = rsmd.getColumnCount();
			String columnName = null;
			while (rs.next()) {
				Customer customer = new Customer();
				for (int i = 1; i <= columnCount; i++) {
					columnName = rsmd.getColumnName(i);
					if (columnName.equalsIgnoreCase("ID"))
						customer.setId(rs.getInt(columnName));
					if (columnName.equalsIgnoreCase("CUSTOMERID"))
						customer.setCustomerId(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("CUSTOMERNAME"))
						customer.setCustomerName(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("IDCARD"))
						customer.setIdCard(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("COMPANYNAME"))
						customer.setCompanyName(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("PROVINCE"))
						customer.setProvince(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("CITY"))
						customer.setCity(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("PHONE"))
						customer.setPhone(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("MOBILE"))
						customer.setMobile(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("QQ"))
						customer.setQQ(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("EMAIL"))
						customer.setEmail(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("BIRTHDAY"))
						customer.setBirthday(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("ISNEW"))
						customer.setIsNew(rs.getInt(columnName));
					if (columnName.equalsIgnoreCase("USERSNO"))
						customer.setUserSno(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("ROLEID"))
						customer.setRoleId(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("CREATETIME"))
						customer.setCreateTime(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("MODIFYTIME"))
						customer.setModifyTime(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("MEMO"))
						customer.setMemo(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("TYPE"))
						customer.setType(rs.getString(columnName));
					if (columnName.equalsIgnoreCase("ASSIGNER"))
						customer.setAssigner(rs.getString(columnName));
				}
				result.add(customer);
			}
			rs.close();
			stmt.close();
		} catch (SQLException e) {
			result = null;
			log.error("ERROR SQL:" + sql);
			e.printStackTrace();
		} finally {
			closeConnection(con);
			return result;
		}
	}

	public Customer insert(Customer customer) throws Exception {
		String sql = "insert into customer(customerId, customerName, idCard, companyName, province, city, phone, "
				+ "mobile, QQ, email, birthday, isNew, userSno, roleId, "
				+ "createTime, memo, assigner)values('"
				+ customer.getCustomerId()
				+ "', '"
				+ customer.getCustomerName()
				+ "', '"
				+ customer.getIdCard()
				+ "', '"
				+ customer.getCompanyName()
				+ "', '"
				+ customer.getProvince()
				+ "', '"
				+ customer.getCity()
				+ "', '"
				+ customer.getPhone()
				+ "', '"
				+ customer.getMobile()
				+ "', '"
				+ customer.getQQ()
				+ "', '"
				+ customer.getEmail()
				+ "', '"
				+ customer.getBirthday()
				+ "', 0, '"
				+ customer.getUserSno()
				+ "', '"
				+ customer.getRoleId()
				+ "', '"
				+ customer.getCreateTime()
				+ "','"
				+ customer.getMemo()
				+ "', "
				+ DaoUtil.setValue(customer.getAssigner()) + ")";
		int result = -1;
		if (update(sql) > -1) {
			sql = "select customer.id, customer.customerId, customer.customerName, customer.idCard, customer.companyName, "
					+ "customer.province, customer.city, customer.phone, customer.mobile, customer.QQ, "
					+ "customer.email, customer.birthday, customer.isNew, baseuser.nickName as userSno, "
					+ "userRole.roleName as roleId, customer.createTime, customer.modifyTime, "
					+ "customer.memo from customer "
					+ "left join baseuser on baseuser.userName = customer.userSno "
					+ "left join userRole on userRole.roleId = baseuser.roleId "
					+ "where customerId='"
					+ customer.getCustomerId()
					+ "' and isNew=0";
			return findSingle(querySingleRow(sql));
		}
		return null;
	}

	public Customer modify(Customer customer) throws Exception {
		String sql = "update customer set customerName='"
				+ customer.getCustomerName() + "', idCard='"
				+ customer.getIdCard() + "', companyName='"
				+ customer.getCompanyName() + "', province='"
				+ customer.getProvince() + "', city='" + customer.getCity()
				+ "', phone='" + customer.getPhone() + "', mobile='"
				+ customer.getMobile() + "', QQ='" + customer.getQQ()
				+ "', email='" + customer.getEmail() + "', isNew=0, birthday='"
				+ customer.getBirthday() + "', userSno='"
				+ customer.getUserSno() + "', roleId='" + customer.getRoleId()
				+ "', modifyTime='" + customer.getModifyTime() + "', memo='"
				+ customer.getMemo() + "' where customerId='"
				+ customer.getCustomerId() + "'";
		update(sql);
		return customer;
	}

	public int insert(Map map) throws Exception {
		StringBuffer fields = new StringBuffer("(");
		StringBuffer values = new StringBuffer(" values(");
		Iterator iter = map.keySet().iterator();
		while (iter.hasNext()) {
			String field = iter.next().toString();
			fields.append(field + ",");

			String value = (String) map.get(field);
			if (value == null || value.trim().equals("")
					|| value.trim().equalsIgnoreCase("null"))
				value = null;
			if (value == null)
				values.append("NULL, ");
			else
				values.append("'" + value + "', ");
		}
		fields.append(" createTime, isNew)");
		values.append(" '" + TimeTool.getSystemTime() + "', 0)");
		String sql = "insert into customer" + fields.toString()
				+ values.toString();
		return update(sql);
	}

	public int modify(Map map) throws Exception {
		StringBuffer tmp = new StringBuffer();
		Iterator iter = map.keySet().iterator();
		while (iter.hasNext()) {
			String field = iter.next().toString();
			String value = (String) map.get(field);
			if (value == null || value.trim().equals("")
					|| value.trim().equalsIgnoreCase("null"))
				value = "";
			tmp.append(field + "='" + value + "', ");
		}
		tmp.append("modifyTime='" + TimeTool.getSystemTime() + "'");
		String sql = "update customer set " + tmp.toString()
				+ " where customerId='" + map.get("CUSTOMERID") + "'";
		return update(sql);
	}

	public int delete(String customerId) throws Exception {
		String sql = null;
		if (customerId.indexOf(",") > 0) {
			customerId = "'" + customerId.replaceAll(",", "','") + "'";
			sql = "delete from customer where customerId in(" + customerId
					+ ")";
		} else
			sql = "delete from customer where customerId='" + customerId + "'";
		return update(sql);
	}

	public List findLessonMen(String tableName, String id) throws Exception {
		String sql = null;
		if (id.indexOf(",") > 0)
			sql = "select * from " + tableName + " where id in(" + id + ")";
		else
			sql = "select * from " + tableName + " where id=" + id;
		return queryMultiColumn(sql);
	}

	public int modifyLessonMen(String tableName, String id, String userSno) {
		String sql = "update " + tableName + " set userSno='" + userSno
				+ "' where id=" + id;
		return update(sql);
	}

	public int modifyUerSno(String customerId, String userSno, String roleId,
			String assigner) {
		String sql = null;
		if (customerId.contains(",")) {
			customerId = "'" + customerId.replaceAll(",", "','") + "'";
			sql = "update customer set userSno='" + userSno + "', roleId='"
					+ roleId + "', assigner='" + assigner
					+ "' where customerId in(" + customerId + ")";
		} else
			sql = "update customer set userSno='" + userSno + "', roleId='"
					+ roleId + "', assigner='" + assigner
					+ "' where customerId='" + customerId + "'";
		return update(sql);
	}

	public int modifyRole(String roleId, String userSno) {
		String sql = "update customer set roleId='" + roleId
				+ "' where userSno='" + userSno + "'";
		return update(sql);
	}

	public int modifyType(String customerId, String typeValue) {
		String sql = null;
		if (customerId.indexOf(",") > 0) {
			customerId = "'" + customerId.replaceAll(",", "','") + "'";
			sql = "update customer set type='" + typeValue
					+ "' where customerId in(" + customerId + ")";
		} else
			sql = "update customer set type='" + typeValue
					+ "' where customerId='" + customerId + "'";
		return update(sql);
	}

	public int modifyMemo(String id, String memo) {
		String sql = "update customer set memo='" + memo + "' where id =" + id;
		return update(sql);
	}

	public synchronized String create() {
		try {
			log.info("开始初始化表customer...");
			String sql = "SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[customer]');";
			List list = this.queryMultiColumn(sql);
			if (list == null) {
				log
						.warn("系统检测失败。\n原因:\n  1.数据库非正常运行;\n  2.帐户没权限不足;\n  3.数据库连接异常。");
				return "系统检测失败。\n原因:\n  1.数据库非正常运行;\n  2.帐户没权限不足;\n  3.数据库连接异常。";
			}
			if (list.isEmpty()) {
				log.info("表customer不存在，开始创建...");
				sql = "/****** 对象:  Table [dbo].[customer]    脚本日期: 06/24/2009 17:40:16 ******/ "
						+ "SET ANSI_NULLS ON;"
						+ "SET QUOTED_IDENTIFIER ON;"
						+ "SET ANSI_PADDING ON;"
						+ "CREATE TABLE [dbo].[customer]("
						+ "[id] [int] IDENTITY(1,1) NOT NULL,"
						+ "[customerId] [varchar](50) NOT NULL,"
						+ "[customerName] [varchar](50) NOT NULL,"
						+ "[companyName] [varchar](100) NULL,"
						+ "[province] [varchar](50) NULL,"
						+ "[city] [varchar](50) NULL,"
						+ "[phone] [varchar](50) NULL,"
						+ "[mobile] [varchar](50) NOT NULL,"
						+ "[QQ] [varchar](50) NULL,"
						+ "[email] [varchar](50) NULL,"
						+ "[birthday] [varchar](20) NULL,"
						+ "[isNew] [int] NOT NULL,"
						+ "[signature] [int] NOT NULL,"
						+ "[signTime] [varchar](20) NULL,"
						+ "[userSno] [varchar](50) NOT NULL,"
						+ "[state] [varchar](50) NULL,"
						+ "[roleId] [varchar](500) NULL,"
						+ "[createTime] [varchar](50) NULL,"
						+ "[modifyTime] [varchar](50) NULL,"
						+ "[memo] [varchar](500) NULL,"
						+ "[amount] [varchar](20) NULL,"
						+ "[payTime] [varchar](20) NULL,"
						+ "CONSTRAINT [PK_customer] PRIMARY KEY CLUSTERED"
						+ "("
						+ "[id] ASC"
						+ ")WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]"
						+ ") ON [PRIMARY];" + "SET ANSI_PADDING OFF;";

				if (this.update(sql) < 0) {
					log.warn("表customer初始化失败!");
					return "表customer初始化失败!";
				}
				log.info("表customer创建成功!");
				return "表customer创建成功!";
			} else {
				log.info("表customer已存在!");
				return "表customer已存在!";
			}
		} catch (Exception e) {
			log.warn("表customer初始化失败!");
			e.printStackTrace();
			return "表customer初始化失败!" + e.toString();
		}
	}
}